/////////////////////////////////////////////////////////////////////////////
/*/	
*	Creator:		Joshua C. Rouzer
*	Title:			Bullet cpp
*	Last Edited:	06/14/2013
*	Summary:		Definition for the bullet class
/*/
/////////////////////////////////////////////////////////////////////////////
#include "Bullet.h"
#include "EntityManager.h"
#include "LevelManager.h"
#include "EventManager.h"
#include "AnimInfo.h"
/////////////////////////////////////////////////////////////////////////////
// Function		: Constructor
// Parameters	: pOwner - The owner of the bullet, prevents suicide
// Notes		: Assigns the owner to provided owner object
/////////////////////////////////////////////////////////////////////////////
CBullet::CBullet(CBaseClass* pOwner){
	m_eType = BULLET;
	m_pOwner = pOwner;
	SetVelX(10);
	SetVelY(10);
	m_nDamage = 10;
	SetDeathY(600);
	SetTeam(pOwner->GetTeam());
	/*AnimSystem = new CAnimationSystem();
	AnimSystem->LoadAnimation("MissileExplosionAnim.xml");
	AnimationInfo = new CAnimInfo();
	if(AnimSystem->FindAnimation("Missile_Explosion") != -1)
		AnimationInfo->SetCurrAnim(AnimSystem->FindAnimation("Missile_Explosion"));
	else
		AnimationInfo->SetCurrAnim(0);
	AnimationInfo->SetOwner(this);
	AnimationInfo->SetIsPlaying(false);

	CurrAnim = AnimSystem->GetAnimations()[AnimationInfo->GetCurrAnim()];
	CurrAnim->SetImageID(AnimSystem->GetAnimations()[AnimationInfo->GetCurrAnim()]->GetImageID());*/
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Destructor
// Notes		: Cleans up any dynamically allocated memory
/////////////////////////////////////////////////////////////////////////////
CBullet::~CBullet(){
	delete AnimationInfo;
	delete AnimSystem;
}

/////////////////////////////////////////////////////////////////////////////
// Function		: Update
// Notes		: Checks if the bullet should die
/////////////////////////////////////////////////////////////////////////////
void CBullet::Update( float fDT ){

	if( GetPosY() < 0 || GetPosY() > GetDeathY() || GetPosX() < 0 || GetPosX() > CLevelManager::GetInstance()->GetCurrLevel()->GetField().m_nWidth )
	{
		// Destroy bullet!
		if( GetType() == BULLET )
			CEntityManager::GetInstance()->RemoveEntity( this );
		else if( GetType() == MISSILE )
		{
			CEventManager::GetInstance()->SendEvent( "MISSILE", nullptr, nullptr, this );
			//CurrAnim->Play(false,CurrAnim->GetIsLoop(),*AnimationInfo);
			SetVelX( 0 );
			SetVelY( 0 );
		}
	}

	CMovingObject::Update(fDT);

	// Animation Playing?
	//if( AnimationInfo->GetIsPlaying() )
	//{
	//	AnimSystem->Update(fDT,AnimationInfo);

	//	// Finished Animation after Update
	//	if( !AnimationInfo->GetIsPlaying() )
	//		CEntityManager::GetInstance()->RemoveEntity( this );
	//}
}

void CBullet::Render(){
	//if( !AnimationInfo->GetIsPlaying() )
		CMovingObject::Render();

	/*if( AnimationInfo->GetIsPlaying() )
		AnimSystem->Render(GetPos(),AnimationInfo);*/
}